Skip to content

refactor: flatten deeply nested logic with early returns and guard clauses - #368

Merged
jvolkman merged 4 commits into
mainfrom
refactor/flatten-nested-logic
Oct 17, 2026
Merged

jvolkman merged 4 commits into
mainfrom
refactor/flatten-nested-logic

Conversation

@jvolkman

@jvolkman jvolkman commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Flattens deeply nested control flow (if/else pyramids) across pycross/private/ and modules/backend_maturin/ using early returns, guard statements with continue, and small focused helper functions:

  • Lock translation (translator_common.bzl, uv_lock_model.bzl, poetry_lock_model.bzl, pylock_lock_model.bzl):
    • Extract _read_project_dict and _resolve_local_dep_constraint in translator_common.bzl using early returns and continue guards; flatten package deduplication, dependency matching, and pin resolution loops in resolve_lock_graph.
    • Extract _resolve_uv_dep_constraint and _parse_sdist_file in uv_lock_model.bzl, and flatten _resolve_package_requires_python, _parse_uv_dependency, and group/member iteration with continue guards.
    • Extract _resolve_pylock_project_pins in pylock_lock_model.bzl and flatten include-group, BFS reachability, and fork-pin construction loops.
    • Flatten _get_files_for_package and group filtering in poetry_lock_model.bzl.
  • Lock resolution, rendering & repo generation (lock_resolver.bzl, lock_common.bzl, lock_repo_creation.bzl, resolved_lock_renderer.bzl, thin_package_repo.bzl, sdist_repo.bzl, pypi_file.bzl, format_extension.bzl, backends.bzl):
    • Extract _synthesize_extra_package in lock_resolver.bzl and use continue guards in _create_package_resolver and _compute_cycle_groups.
    • Extract _create_remote_file_repo in lock_repo_creation.bzl and _extract_href in pypi_file.bzl.
    • Flatten workspace validation and rendering loops in lock_common.bzl, format_extension.bzl, backends.bzl, resolved_lock_renderer.bzl, thin_package_repo.bzl, and sdist_repo.bzl.
  • Cycle, marker & runtime rules (cycle_dep_needed.bzl, cycle_member_marker_deps.bzl, pep508_marker_values.bzl, wheel_library.bzl, modules_mapping.bzl, build/rules/common_attrs.bzl):
    • Extract _register_wheel_install_action and _build_venv_symlinks in wheel_library.bzl, _node_env in cycle_dep_needed.bzl, and _toolchain_py3_runtime in pep508_marker_values.bzl.
    • Flatten loop conditions in cycle_member_marker_deps.bzl, modules_mapping.bzl, and common_attrs.bzl.
  • Python tools (inspect_package.py, cc_toolchain.py, generate_cargo_lock.py, rust_common.py):
    • Extract _find_cargo_toml_dir_from_pyproject in generate_cargo_lock.py (with open(pyproject_path) inside the fallback try/except) and _symlink_stdlib in rust_common.py.
    • Use early returns and continue guards in inspect_package.py and cc_toolchain.py (get_wrapper_flags now matches exact flag names via partition("=") before reading split_cflags[i + 1], avoiding an IndexError if the last flag only shares a prefix like --sysroots).

if _matches(name):
return z.read(name).decode("utf-8")
elif archive_path.name.endswith((".tar.gz", ".tgz", ".tar.bz2", ".tar")):
return ""

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use an elif here

@jvolkman
jvolkman merged commit 3d08eb9 into main Oct 17, 2026
76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant